package com.atgouwu.aiparent.springai.controller;

import jakarta.annotation.Resource;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

/**
 * 整合DeepSeek：
 */
@RestController
@RequestMapping("/deepseek")
public class DeepSeekController {
    @Resource
    private ChatClient chatClient;

    /**
     * http://localhost:9001/deepseek/chat?prompt=介绍一下你自己
     */
    @GetMapping("/chat")
    public String generate(@RequestParam(value = "prompt", defaultValue = "Tell me a joke") String prompt) {
        return chatClient.prompt() //创建新提示构建器
                .user(prompt) //提示词
                .call() //阻塞式响应
                .content(); //获取返回内容
    }

    /**
     * http://localhost:9001/deepseek/stream?prompt=介绍一下你自己
     */
    @GetMapping(value = "/stream", produces = "text/html;charset=utf-8")
    public Flux<String> stream(@RequestParam(value = "prompt", defaultValue = "Tell me a joke") String prompt) {
        return chatClient.prompt() //创建新提示构建器
                .user(prompt) //提示词
                .stream() //流式响应
                .content(); //获取返回内容流
    }
}
